﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace NRemedy.MVC.UI
{
    public class NeedKeyAttribute : ActionMethodSelectorAttribute
    {
        private string[] _needKeys = null;

        public const string ARRequestID = "requestid";

        public NeedKeyAttribute(params string[] NeedKeys)
        {
            _needKeys = NeedKeys;
        }


        public override bool IsValidForRequest(ControllerContext controllerContext, System.Reflection.MethodInfo methodInfo)
        {
            if (_needKeys == null)
                return true;
            foreach(var k in _needKeys)
            {
                if (!controllerContext.HttpContext.Request.Form.AllKeys.Contains(k))
                    return false;
            }

            return true;
        }
    }
}
